package com.wavehi.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Author WaveHi
 * @Date 18/10/2021 上午 11:50
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Encapsulate the enhancement operation.
 */
@Aspect
@Component
public class EnhancementOperation {
    @Before(value = "execution(* com.wavehi.aspectj.Operation01.add(..))")
    public void before() {
        System.out.println("Before..");
    }
    @AfterReturning(value = "execution(* com.wavehi.aspectj.Operation01.add(..))")
    public void afterReturning() { System.out.println("AfterReturning..."); }
    @Around(value = "execution(* com.wavehi.aspectj.Operation01.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) {
        System.out.println("Around..Before!");
        try {
            //Call the enhanced method.
            proceedingJoinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("Around...After!");
    }
    @AfterThrowing(value = "execution(* com.wavehi.aspectj.Operation01.add(..))")
    public void afterThrowing() { System.out.println("AfterThrowing..."); }
    @After(value = "execution(* com.wavehi.aspectj.Operation01.add(..))")
    public void after() { System.out.println("After..."); }
}
